package com.example.qu_tao.View;

import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.qu_tao.R;
import com.google.android.material.textfield.TextInputEditText;

public class ShiMingRenZhengActivity extends AppCompatActivity {
    private TextInputEditText etRealName;
    private TextInputEditText etIdCard;
    private Button btnSubmit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shimingrenzheng);

        // 初始化视图
        initViews();

        // 设置点击监听
        setClickListeners();
    }

    private void initViews() {
        // 返回按钮
        findViewById(R.id.ivBack).setOnClickListener(v -> finish());

        etRealName = findViewById(R.id.etRealName);
        etIdCard = findViewById(R.id.etIdCard);
        btnSubmit = findViewById(R.id.btnSubmit);
    }

    private void setClickListeners() {
        btnSubmit.setOnClickListener(v -> {
            String name = etRealName.getText().toString().trim();
            String idCard = etIdCard.getText().toString().trim();

            if (name.isEmpty()) {
                Toast.makeText(this, "请输入真实姓名", Toast.LENGTH_SHORT).show();
                return;
            }

            if (idCard.isEmpty()) {
                Toast.makeText(this, "请输入身份证号码", Toast.LENGTH_SHORT).show();
                return;
            }

            if (!isValidIdCard(idCard)) {
                Toast.makeText(this, "请输入有效的身份证号码", Toast.LENGTH_SHORT).show();
                return;
            }

            // 这里添加实名认证的网络请求
            submitRealNameAuth(name, idCard);
        });
    }

    // 简单的身份证号验证
    private boolean isValidIdCard(String idCard) {
        // 这里可以添加更复杂的验证逻辑
        return idCard.length() == 18 || idCard.length() == 15;
    }

    private void submitRealNameAuth(String name, String idCard) {
        // 这里实现实名认证的网络请求
        // 示例代码，实际应用中需要替换为真实的API调用
        Toast.makeText(this, "实名认证提交成功", Toast.LENGTH_SHORT).show();
        finish();
    }
}
